package com.mlog.njyjy.ndop.msg.admin.util.boot;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.ConfigurableApplicationContext;

import java.net.Inet4Address;
import java.net.UnknownHostException;


@Slf4j
public class StartBootServiceUrlUtil {
    public static void printUrl(ConfigurableApplicationContext ctx) {
        try {
            String host = Inet4Address.getLocalHost().getHostAddress();
            TomcatServletWebServerFactory tomcatServletWebServerFactory = (TomcatServletWebServerFactory) ctx.getBean("tomcatServletWebServerFactory");
            int port = tomcatServletWebServerFactory.getPort();
            String contextPath = tomcatServletWebServerFactory.getContextPath();
            String url = "http://" + host + ":" + port + contextPath + "/";
            String swg = "http://" + host + ":" + port + contextPath + "/swagger-ui.html";
            log.info("success http :" + url);
            log.info("success swg :" + swg);

        } catch (UnknownHostException e) {
            log.error("fail");
        }
    }
}
